@import '../../styles/default.less';
@import '../../styles//theme/base.less';

.center() {
  display: flex;
  align-items: center;
  justify-content: center;
}

.switch {
  position: relative;
  display: inline-block;
  box-sizing: border-box;
  padding-top: 2px;
  font-size: 14px;
  &:hover {
    cursor: pointer;
  }
  &.small {
    width: 42px;
  }
  &.medium {
    width: 54px;
  }
  &.large {
    width: 74px;
  }

  &.disabled {
    cursor: not-allowed;
    .switch-core {
      background-color: @color-gray-2;
      border-color: @color-gray-3;
      .switch-btn {
        background-color: @color-gray-3;
      }
    }
    // 点击切换时的样式
    &.checked-small {
      .switch-core {
        background-color: @color-primary-4;
        .switch-btn {
          background-color: @color-gray-2;
        }
      }
    }
    &.checked-medium {
      .switch-core {
        background-color: @color-primary-4;
        .switch-btn {
          background-color: @color-gray-2;
        }
      }
    }
    &.checked-large {
      .switch-core {
        background-color: @color-primary-4;
        .switch-btn {
          background-color: @color-gray-2;
        }
      }
    }
  }

  .switch-core {
    position: relative;
    display: inline-block;
    box-sizing: border-box;
    margin: 2px;
    background: #dcdfe6;
    border: 1px solid #dcdfe6;
    outline: none;
    &.small {
      width: 38px;
      height: 20px;
      border-radius: 10px;
      transform: translateY(1px);
      .switch-btn {
        position: absolute;
        top: 2px;
        left: 1px;
        width: 14px;
        height: 14px;
      }
    }
    &.medium {
      width: 50px;
      height: 26px;
      border-radius: 18px;
      transform: translateY(1px);
      .switch-btn {
        position: absolute;
        top: 2px;
        left: 2px;
        width: 20px;
        height: 20px;
      }
    }
    &.large {
      width: 70px;
      height: 32px;
      border-radius: 20px;
      transform: translateY(1px);
      .switch-btn {
        position: absolute;
        top: 3px;
        left: 2px;
        width: 24px;
        height: 24px;
      }
    }
    .switch-btn {
      position: absolute;
      top: 1px;
      left: 1px;
      width: 16px;
      height: 16px;
      text-align: center;
      background-color: #fff;
      border-radius: 100%;
      transition: all 0.3s;
      .center();
    }
  }
  // 点击切换时的样式
  &.checked-small {
    .switch-core {
      background-color: @color-primary-6;
      border-color: @color-gray-2;
    }
    .switch-btn {
      transform: translateX(19px);
    }
  }
  &.checked-medium {
    .switch-core {
      background-color: @color-primary-6;
      border-color: @color-gray-2;
    }
    .switch-btn {
      transform: translateX(23px);
    }
  }
  &.checked-large {
    .switch-core {
      background-color: @color-primary-6;
      border-color: @color-gray-2;
    }
    .switch-btn {
      transform: translateX(39px);
    }
  }
}
